var dataSource_SalesInput;
var rowSelected_SalesInput;
var totalDiscAmount = 0;
var selectTgl;


var mRecordSalesInpuit = Ext.data.Record.create
	(
		[
		   {name: 'BARDESCR', mapping:'BARDESCR'},
		   {name: 'ARTCEXT', mapping:'ARTCEXT'},
		   {name: 'SIZE', mapping:'SIZE'},
		   {name: 'COLOR', mapping:'COLOR'},
		   {name: 'SLSPRICE', mapping:'SLSPRICE'},
		   {name: 'DISCARMOUNT', mapping:'DISCARMOUNT'},
		   {name: 'BARCODE', mapping:'BARCODE'}
		]
	);

var currentRowSelected_SalesInput =
{
    data: Object,
    details: Array,
    row: 0
};

function BindingData_SalesInput(Query)
{
	dataSource_SalesInput.load
    (
		{
			params:
			{
				Skip: 0,
				Take: 50,
				Sort: '',
				Sortdir: 'ASC',
				target:'Trx_BindSales',
				param: Query
			}
		}
    );    
    return dataSource_SalesInput;
}

function BindingDataBarang_SalesInput(Criteria,row,flag,dsStore,urut)
{
	// if(flag)
	// {}
	// else
	// {
		Ext.Ajax.request
		(
			{
				url: "./Module.mvc/ExecProc",
				params: 
				{
					UserID: 'Admin',
					ModuleID: 'GetBindBarang',
					Params:	Criteria 
				},
				success: function(o) 
				{
					
					var cst = Ext.decode(o.responseText);
					if (cst.success === true) 
					{	
						row.data.BARDESCR = cst.DESCRIPT;
						row.data.ARTCEXT = cst.ITEMID;
						row.data.SIZE = cst.SIZE;
						row.data.COLOR = cst.COLOR;
						row.data.SLSPRICE = cst.PRICE;
						row.data.DISCARMOUNT = cst.DISC;
						row.data.BARCODE=cst.BARCODE;
						dsStore.removeAt(dsStore.getCount()-1);
						dsStore.insert(urut,row);
					}
					// else
					// {				
						
					// };
				}

			}
		);
	}
//}


function BindingDataStore_SalesInput()
{
    dsComboStore_SalesInput.load
    (
        {
            params:
            {
                Skip: 0,
                Take: 1000,
                Sort: '',
                Sortdir: 'ASC',
                target:'Store',
                param: ''
            }            
        }
    )
}

function prosesGetDataBarang_SalesInput(Criteria)
{
	var params = 
	{
		Table: 'ProsesBindData',   
		BARCODE: Criteria
	}
	return params;
}

function SaveSalesInput(first)
{
	if (first == true)
	{
		if(validationSalesInput() == 1)
		{
			Ext.Ajax.request
			(
			{
					
				url: "./Datapool.mvc/CreateDataObj",
				params: params_SalesInput(),
				success: function(o) 
				{
					var cst = Ext.decode(o.responseText);					
					if (cst.success === true) 
					{
						alert('done');
					}
					else if (cst.success === false && cst.pesan===0)
					{
						alert('fail');
					}
					else 
					{
						alert('error');
					}
				}
			}
			)
		}
	}
	else
	{
		Ext.Ajax.request
		({		
			url: "./Datapool.mvc/UpdateDataObj",
			params: params_SalesInput(),
			success: function(o) 
			{
				var cst = Ext.decode(o.responseText);					
				if (cst.success === true) 
				{
					alert('done');
				}
				else if (cst.success === false && cst.pesan===0)
				{
					alert('fail');
				}
				else 
				{
					alert('error');
				}
			}
		})
	}
}

function params_SalesInput()
{
	var params =
	{
		Table: 'TransactSales',
		ListBarang: getDataBarang(),
		FieldCount: 9,
		ListCount: dataSource_SalesInput.getCount(),
		NOTA: Ext.get('cboNoNota').getValue(),
		SALESDATE:Ext.getCmp('date_SalesInput').getValue(),
		SALESNO: Ext.get('txtIdSales_SalesInput').getValue(),
		FLAG: 0,
		TOTDISAMT: totalDiscAmount
		
	}
	return params;
}

function LoadNoNota(critera)
{
	 dsNota.load
    (
        {
            params:
            {
                Skip: 0,
                Take: 1000,
                Sort: 'SLSNOTA',
                Sortdir: 'ASC',
                target:'TransactSales',
                param: "where SLSDATE = '" + critera + "' and slsflag = 0 "
            }            
        }
    )
}

